function viewCkshXshtDetail(id) {
    $.window({
        iconCls: 'icon-tip',
        title: "详细信息",
        url: $.webPath() + "/htgl/xshtgl/xshtgl_detail?xshtId=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}

$(function(){

    $("#cksh_xsdmx_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    //=================销售单 出售联 提货单 送货单  按钮切换===================
    $('#xsd_csl').click(function () {
        $("#xsddy_csl").show();
        $("#xsddy_thd").hide();
        $("#xsddy_shd").hide();

        $("[name='bhs']").show();
        $("[name='hs']").show();
        $("[name='wse']").show();
        $("[name='hse']").show();
        $("[name='se']").show();
    });

    $('#xsd_thd').click(function () {
        $("#xsddy_csl").hide();
        $("#xsddy_thd").show();
        $("#xsddy_shd").hide();

        $("[name='bhs']").show();
        $("[name='hs']").show();
        $("[name='wse']").show();
        $("[name='hse']").show();
        $("[name='se']").show();
    });

    $('#xsd_shd').click(function () {
        $("#xsddy_csl").hide();
        $("#xsddy_thd").hide();
        $("#xsddy_shd").show();

        $("[name='bhs']").hide();
        $("[name='hs']").hide();
        $("[name='wse']").hide();
        $("[name='hse']").hide();
        $("[name='se']").hide();
    });
    //================勾选所选项==================================
    $('#xsd_yfsl').bind('click', function () {   //==应发数量
        var yfsl = $('#xsd_yfsl_1').val();
        if (yfsl == 'on') {
            $("[name='yfsl']").hide();
            $('#xsd_yfsl_1').val('off');
        } else if (yfsl == 'off') {
            $("[name='yfsl']").show();
            $('#xsd_yfsl_1').val('on');
        }
    });
    $('#xsd_sfsl').bind('click', function () { //==实发数量
        var sfsl = $('#xsd_sfsl_1').val();
        if (sfsl == 'on') {
            $("[name='sfsl']").hide();
            $('#xsd_sfsl_1').val('off');
        } else if (sfsl == 'off') {
            $("[name='sfsl']").show();
            $('#xsd_sfsl_1').val('on');
        }
    });
    $('#xsd_kcdj').bind('click', function () {   //==库存单价
        var kcdj = $('#xsd_kcdj_1').val();
        if (kcdj == 'on') {
            $("[name='kcdj']").hide();
            $('#xsd_kcdj_1').val('off');
        } else if (kcdj == 'off') {
            $("[name='kcdj']").show();
            $('#xsd_kcdj_1').val('on');
        }
    });
    $('#xsd_kcje').bind('click', function () { //==库存金额
        var kcje = $('#xsd_kcje_1').val();
        if (kcje == 'on') {
            $("[name='kcje']").hide();
            $('#xsd_kcje_1').val('off');
        } else if (kcje == 'off') {
            $("[name='kcje']").show();
            $('#xsd_kcje_1').val('on');
        }
    });
    $('#xsd_bhs').bind('click', function () { //==出售单价(不含税)
        var bhs = $('#xsd_bhs_1').val();
        if (bhs == 'on') {
            $("[name='bhs']").hide();
            $('#xsd_bhs_1').val('off');
        } else if (bhs == 'off') {
            $("[name='bhs']").show();
            $('#xsd_bhs_1').val('on');
        }
    });
    $('#xsd_hs').bind('click', function () { //== 出售单价(含税)
        var hs = $('#xsd_hs_1').val();
        if (hs == 'on') {
            $("[name='hs']").hide();
            $('#xsd_hs_1').val('off');
        } else if (hs == 'off') {
            $("[name='hs']").show();
            $('#xsd_hs_1').val('on');
        }
    });
    $('#xsd_wse').bind('click', function () { //==无税额
        var wse = $('#xsd_wse_1').val();
        if (wse == 'on') {
            $("[name='wse']").hide();
            $('#xsd_wse_1').val('off');
        } else if (wse == 'off') {
            $("[name='wse']").show();
            $('#xsd_wse_1').val('on');
        }
    });
    $('#xsd_hse').bind('click', function () { //==含税额
        var hse = $('#xsd_hse_1').val();
        if (hse == 'on') {
            $("[name='hse']").hide();
            $('#xsd_hse_1').val('off');
        } else if (hse == 'off') {
            $("[name='hse']").show();
            $('#xsd_hse_1').val('on');
        }
    });
    $('#xsd_se').bind('click', function () { //==税额
        var se = $('#xsd_se_1').val();
        if (se == 'on') {
            $("[name='se']").hide();
            $('#xsd_se_1').val('off');
        } else if (se == 'off') {
            $("[name='se']").show();
            $('#xsd_se_1').val('on');
        }
    });
    //=============================================================
})

$('#cksh_tabs').tabs({
    border: false,
    onSelect: function (title) {
        if (title == "销售单打印") {
            $.ajax({
                type: "POST",
                url: $.webPath() + '/xsgl/xsdgl/xsdDetail?xsdId=' + $("#xsd_id").val(),
                dataType: "html",
                beforeSend: function () {
                    $.messager.progress();
                },
                success: function (data) {
                    $.messager.progress("close");
                    $('#xsdy_xsd_id').html(data);
                    //=====================保供销售显示库存单价和库存金额    [name='bgxs_name']
                    var xslx = $("#xsd_detail_xslx").val();
                    if (xslx == "bgxs") {
                        $("[name='kcdj']").show(); //kcje
                        $("[name='kcje']").show();
                    } else {
                        $("[name='kcdj']").hide(); //kcje
                        $("[name='kcje']").hide();
                    }
                }
            });
        }
    }
});

function xsdyPrintPreview() {
    if ($("#xsdzt").val() == "ybc") {
        alert("此单据必须提交后才能进行打印!");
        return;
    }
    var LODOP = getLodop(document.getElementById('XSD_LODOP_OB'), document.getElementById('XSD_LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览销售单");

    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsdy_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsdy_xsd_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsdy_detail_id").innerHTML + "</div>";
    var xsd_xsdh = $("#xsd_xsdh").val();
    var xsd_ewmtime = $("#xsd_ewmtime").val();

//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
//    LODOP.ADD_PRINT_BARCODE(50, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);

    LODOP.PREVIEW();

//
//    var strStyle="<style> table,td,th {border-width: 1px;border-style: solid;border-collapse: collapse}</style>"
//    LODOP.ADD_PRINT_TABLE(128,"5%","90%",314,strStyle+document.getElementById("div2").innerHTML);
//    LODOP.SET_PRINT_STYLEA(0,"Vorient",3);
//    LODOP.ADD_PRINT_HTM(20,"5%","90%",109,document.getElementById("div1").innerHTML);
//    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
//    LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);
//    LODOP.ADD_PRINT_HTM(444,"5%","90%",54,document.getElementById("div3").innerHTML);
//    LODOP.SET_PRINT_STYLEA(0,"ItemType",1);
//    LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

};

//销售单打印
function xsdyPrint() {
    var LODOP = getLodop(document.getElementById('XSD_LODOP_OB'), document.getElementById('XSD_LODOP_EM'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("打印销售单");
    LODOP.SET_PRINT_STYLE("FontSize", 18);

    /*var inputs = document.getElementById("xsdy_id").getElementsByTagName("input");
     for (var i = 0; i < inputs.length; i++) {
     inputs[i].setAttribute("value", inputs[i].value);
     }*/
    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltop = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsdy_print_id").innerHTML + "</div>";
    var strFormHtmlbody = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsdy_xsd_id").innerHTML + "</div>";
    var strFormHtmlBottom = strBodyStyle + "<div class='textcon'>" + document.getElementById("xsdy_detail_id").innerHTML + "</div>";
    var xsd_xsdh = $("#xsd_xsdh").val();
    var xsd_ewmtime = $("#xsd_ewmtime").val();

//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
//    LODOP.ADD_PRINT_HTM(50, 80, "82%", "90%", strFormHtmltop + strFormHtmlbody + strFormHtmlBottom);
//    LODOP.ADD_PRINT_BARCODE(50, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_PAGESIZE(0, '2600', '1230', "CreateCustomPage");
    LODOP.ADD_PRINT_TABLE(135, "1.5%", "90%", 350, strFormHtmlbody);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltop);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottom);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
//    LODOP.ADD_PRINT_BARCODE(20, "85%", 90, 90, 'QRCode', xsd_xsdh + " " + xsd_ewmtime);
//    LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 3);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);
    LODOP.PREVIEW();
};

function CreatePrintPage1() {
    if ($("#xsdzt").val() == "ybc") {
        alert("此单据必须提交后才能进行打印!");
        return;
    }

    var xsdId = $("#xsd_id").val();
    var shdw = $("#xsddetail_kh").val();
    var thgs = $("#xsddetail_xsgs").val();
    var xsdDzck = $("#xsd_thck_detail").val();
    var xsdDzckDz = $("#xsd_thzckdz_detail").val();
    var xsdZdrq = $("#xsddetail_sxsj").val();
    var arg_xsdZdrq = xsdZdrq.split("-");
    var xsdZdrq_year = arg_xsdZdrq[0];
    var xsdZdrq_month = arg_xsdZdrq[1];
    var xsdZdrq_day = arg_xsdZdrq[2];
    var xsdThrq = $("#xsddetail_jhrq").val();
    var arg_xsdThrq = xsdThrq.split("-");
    var xsdThrq_year = arg_xsdThrq[0];
    var xsdThrq_month = arg_xsdThrq[1];
    var xsdThrq_day = arg_xsdThrq[2];
    var xsdBz = $("#xsd_bz").val();
    var xsdXtdh = $("#xsddetail_xsdh").val();
    var ysgjList = $("#ysgjList").val();

    $.post($.webPath() + '/xsgl/xsdgl/xsdDetailForTd',
        {'xsdId': xsdId},
        function (mxData) {
            var json = $.parseJSON(mxData);

            var LODOP = getLodop(document.getElementById('XSD_LODOP_OB'), document.getElementById('XSD_LODOP_EM'));
            LODOP.PRINT_INITA(-10, 0, 1004, 697, "");
            LODOP.ADD_PRINT_SETUP_BKIMG("<img src='" + $.webPath() + "/images/1234.jpg'/>");
            LODOP.SET_PRINT_PAGESIZE(0, 2550, 1770, "A4");
            LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW", 1);
//            LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT",'Auto-Width');
            LODOP.SET_PREVIEW_WINDOW(1, 0, 0, 0, 0, '');
            LODOP.ADD_PRINT_TEXT(86, 588, 151, 36, thgs);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(193, 162, 271, 22, shdw);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(214, 180, 235, 20, ysgjList);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(233, 164, 267, 20, xsdDzck);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(234, 504, 163, 20, xsdDzckDz);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(566, 161, 779, 20, "销售单号:" + xsdXtdh + "   " + xsdBz);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(167, 156, 49, 24, xsdZdrq_year);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(168, 471, 49, 24, xsdThrq_year);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
//            LODOP.ADD_PRINT_TEXT(168, 763, 183, 25, xsdXtdh);
            LODOP.ADD_PRINT_TEXT(168, 220, 33, 24, xsdZdrq_month);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(168, 272, 33, 24, xsdZdrq_day);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(168, 533, 33, 24, xsdThrq_month);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(168, 578, 33, 24, xsdThrq_day);
            LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            var js = 0;
            var sbsl = 0;
            var ckjs = 0;
            var cksl = 0;
            var hsj = 0;
            var je = 0;
            $.each(json, function (i, val) {
                js += val.js == null ? 0 : val.js;
                sbsl += val.sbsl == null ? 0 : val.sbsl;
                ckjs += val.ck_js == null ? 0 : val.ck_js;
                cksl += val.ck_sbsl == null ? 0 : val.ck_sbsl;
                hsj += val.hsj == null ? 0 : val.hsj;
                je += (val.hsj * val.sbsl);
                //   LODOP.ADD_PRINT_TEXT(277 + (i * 22), 90, 80, 20, val['wzgg.code']);
                //  LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 165, 53, 20, val['wzgg.name']);
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 218, 52, 20, val['cd.z']);
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 274, 65, 20, val['wzgg.cz']);
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 330, 55, 20, val['wzgg.ggxh']);
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                //    LODOP.ADD_PRINT_TEXT(277 + (i * 22), 384, 55, 20, val['kh.khbm']);
                //  LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 434, 68, 20, !val.js ? 0.0000 : val.js);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 505, 83, 20, !val.sbsl ? 0.0000 : formatSl(val.sbsl, ","));
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 584, 84, 20, !val.ck_js ? '' : val.ck_js);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 667, 110, 20, !val.ck_sbsl ? '' : formatSl(val.ck_sbsl, ","));
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 773, 81, 20, !val.hsj ? 0.0000 : formatJe2(val.hsj, ","));
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                LODOP.ADD_PRINT_TEXT(277 + (i * 22), 848, 100, 20, formatJe(val.hsj * val.sbsl, ","));
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            });
            LODOP.ADD_PRINT_TEXT(450, 435, 70, 20, js);
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(450, 501, 79, 20, formatSl(sbsl, ","));
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(450, 582, 84, 20, '');
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
            LODOP.ADD_PRINT_TEXT(450, 671, 105, 20, '');
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
//            LODOP.ADD_PRINT_TEXT(450,771,80,20,formatJe(hsj,","));
//            LODOP.SET_PRINT_STYLEA(0,"Bold",1);
            LODOP.ADD_PRINT_TEXT(450, 848, 100, 20, formatJe(je, ","));
            LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

            //LODOP.PRINT_DESIGN();
            LODOP.PREVIEW();
        }
    );

};